<?php
defined('__JF')
		or die('Direct access is not allowed');
/*
 * Created on 01.12.2008
 */
final class JF_DirUtil {

	public static function read($sDirpath, $sType = 'both')
	{
		$aResult = array();
		if (is_dir($sDirpath)) {
			$sDirpath = realpath($sDirpath);
			if ($rPointer = opendir($sDirpath)) {
		  		while (false !== ($rFP = readdir($rPointer))) {
		  			if (($rFP <> '.') && ($rFP <> '..')) {
						switch ($sType) {
							case 'dir':
								if (is_dir($sDirpath . '/' . $rFP)) {
									array_push($aResult, $rFP);
								}

								break;

							case 'file':
								if (is_file($sDirpath . '/' . $rFP)) {
									array_push($aResult, $rFP);
								}

								break;

							case 'both':
								array_push($aResult, $rFP);
								break;
						}

		  			}

		  		}

		  		closedir($rPointer);
			}

			return $aResult;
		}
		else {
			throw new JF_IOException('Dir ' . $sDirpath . ' not exists');
		}

	}

}